<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>兑换确认</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<include file="public/comm" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav fs_xl">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">兑换确认</h1>
		</header>
		<div class="mui-content fs_xl" style="background: #f4f4f4;">
			<div class="dz_xz cls">
				<div class="dz_ico">
					<i class="mui-icon mui-icon-location"></i>
				</div>
				<div class="dz_info">
					<p class="fs_m">{$address.consignee}<span>{$address.mobile}</span></p>
					<p class="fs_xs">{$address.address}</p>
				</div>
				<div class="dz_rt_ico">
					<a class="mui-icon mui-icon-arrowright" href="{:U('User/address_list')}"></a>
				</div>
			</div>
			<div class="dd_qr">
				<div class="dd_tit">兑换详情</div>
				<div class="dd_info cls">
					<div class="dd_info_lt">
						<img src="{$exchange_info.original_img}" />
					</div>
					<div class="dd_info_rt">
						<p class="db_qs">{$exchange_info.goods_name}</p>
						<p class="db_name fs_s"><span class="fs_xxl">{$exchange_info.exchange_integral}</span>银酒币</p>
					</div>
				</div>
			</div>
			<div class="db_zf fs_xl" style="height: initial;line-height: 3.43em;">
				<p class="cls">
					<span class="fs_l" style="line-height: 3px;">兑换数量</span>
					<span class="mui-numbox fs_l" data-numbox-min='1' style="margin-top: 0.6em;margin-left: 0.6em;float: right;height: 2.5em;">
						<button id="btn2" class="mui-btn mui-btn-numbox-minus fs_l" style="" type="button">-</button>
						<input id="box" class="mui-input-numbox fs_l" type="number" style="vertical-align: top;" />
						<button id="btn1" class="mui-btn mui-btn-numbox-plus fs_l" style="" type="button">+</button>
					</span>
				</p>
<!-- 				<p><span class="fs_l">支付银酒币</span><span class="fs_xxs"><em class="fs_xxi">{$exchange_info.exchange_integral}</em>.00</span></p> -->
			</div>
			<div class="db_hq">
				<div class="db_hq_tit fs_l">配送方式</div>
				<p class="fs_m"><lable><input class="radio" name="shipping" type="radio" value="平台配送" checked="checked" />平台配送</lable></p>
				<p class="fs_m"><lable><input class="radio" name="shipping" type="radio" value="货到付款" />货到付邮</lable></p>
			</div>
			<div class="dh_pay">
				<div class="db_hq_tit fs_l">结算</div>
				<p class="fs_m">商品价格：<span class="dh_jage">{$exchange_info.exchange_integral}</span>银酒币</p>
				<p class="fs_m">物流费用：<span class="dh_wuliu">1200</span>银酒币</p>
				<p class="fs_m">总计：<span class="dh_zongjia"></span>银酒币</p>
			</div>
			<div class="db_pay fs_xl">
				<a class="" href="javascript:void(0)" id="exchange">立即兑换</a>
			</div>
		</div>
		<script type="text/javascript">
			$(".db_hq span").text($(".db_hq span").text().substring(0,3)+"****"+$(".db_hq span").text().substring(7,11)); 
			$(function(){
				$('.radio').click(function(){
 					if($(this).val() == "货到付款"){
 						$(".dh_wuliu").text("0");
 						var price = $(".fs_xxi").text();
 						var num = $("#box").val();
 						var total = {$exchange_info.exchange_integral} * num;
 						$(".dh_jage").text(total);
 						$(".dh_zongjia").text(total);
 					}else{
 						$(".dh_wuliu").text("1200");
 						var price = $(".fs_xxi").text();
 						var num = $("#box").val();
 						var total = {$exchange_info.exchange_integral} * num;
 						$(".dh_jage").text(total);
 						var pri_sum1=parseInt($(".dh_jage").text())+parseInt(pri_m);
 						$(".dh_zongjia").text(pri_sum1);
 					}
				})

				var pri_s=$(".dh_jage").text();
				var pri_m=$(".dh_wuliu").text();
				var pri_sum=parseInt(pri_s)+parseInt(pri_m);
				$(".dh_zongjia").text(pri_sum);
				document.getElementById("btn1").addEventListener('tap', function(event){
					var price = $(".fs_xxi").text();
					var num = $("#box").val();
					var total = {$exchange_info.exchange_integral} * num;
					$(".dh_jage").text(total);
					var pri_sum1=parseInt($(".dh_jage").text())+parseInt(pri_m);
					$(".dh_zongjia").text(pri_sum1);
// 					$(".fs_xxi").text(total);
				});
				document.getElementById("btn2").addEventListener('tap', function(event){
					var num = $("#box").val();
					var total = {$exchange_info.exchange_integral} * num;
					$(".dh_jage").text(total);
					var pri_sum1=total+parseInt(pri_m);
					$(".dh_zongjia").text(pri_sum1);
// 					$(".fs_xxi").text(total);
				});
				$("#box").change(function(){
					var num = $("#box").val();
					var total = {$exchange_info.exchange_integral} * num;
					$(".dh_jage").text(total);
					var pri_sum1=parseInt($(".dh_jage").text())+parseInt(pri_m);
					$(".dh_zongjia").text(pri_sum1);
				})
				
				$("#exchange").click(function(){
					var goods_id = {$exchange_info.goods_id};
					var num = $("#box").val();
					var address_id = {$address.address_id};
					var shipping_name = $('input:radio[name="shipping"]:checked').val();
					$.ajax({
						type:'POST',
						url:"/mobile/exchange/create_order",
						data:{"goods_id":goods_id,"num":num,"address_id":address_id,"shipping_name":shipping_name},
						dataType:"json",
						success:function(data){
							alert(data.msg);
							if(data.status == 1){
								location.href="/mobile/exchange/exchange_record";
							}
						},
					});
				});
			});
		</script>
	</body>

</html>